﻿/// <reference path="wwwroot/lib/ydmjui/static/plugins/jquery/jquery.tmpl.js" />
var gulp = require('gulp');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var rimraf = require("rimraf");
var merge = require('merge-stream');
var cssmin = require("gulp-cssmin");

var webroot = "./root/";
var paths = {
    js: webroot + "js/views/**/*.js",
    minJs: webroot + "js/views/**/*.min.js",
    concatJsDest: webroot + "js/site.min.js",

    css: webroot + "css/**/*.css",
    minCss: webroot + "css/**/*.min.css",
    concatCssDest: webroot + "css/site.min.css",
    exceptCss: webroot + "css/**/login.css"
};

//gulp.task("min:js", function () {
//    return gulp.src([paths.js, "!" + paths.minJs], { base: "." })  // 源文件
//        .pipe(concat(paths.concatJsDest)) // 目标文件
//        .pipe(uglify())   // 混淆文件
//        .pipe(gulp.dest("."));    // 将混淆后文件放入目标文件夹
//});
gulp.task("min:css", function () {
    var streams = [
        gulp.src([
            "wwwroot/lib/YdmJUI/topjui/css/topjui.core.min.css",
            "wwwroot/lib/YdmJUI/topjui/css/topjui.button.css",
            "wwwroot/lib/YdmJUI/static/plugins/layui/css/layui.css",
            "wwwroot/lib/jquery-loadmask/jquery.loadmask.min.css"
        ])
            .pipe(cssmin())
            .pipe(concat("jui.min.css"))
            .pipe(gulp.dest("wwwroot/lib/jui/css/"))
    ];

    return merge(streams);
});

gulp.task("min:js", function () {
    var streams = [
        gulp.src([
            "wwwroot/lib/YdmJUI/static/plugins/jquery/jquery.min.js",
            "wwwroot/lib/layer/layer.js",
            "wwwroot/lib/YdmJUI/static/plugins/jquery/jquery.cookie.js",
            "wwwroot/lib/jquery-loadmask/jquery.loadmask.min.js",
            "wwwroot/lib/YdmJUI/static/plugins/jquery/jquery.tmpl.min.js",
            "wwwroot/lib/YdmJUI/static/public/js/topjui.config.js",
            "wwwroot/lib/YdmJUI/topjui/js/topjui.core.min.js",
            "wwwroot/lib/YdmJUI/topjui/js/locale/topjui.lang.zh_CN.js",
            "wwwroot/lib/abp-web-resources/abp.js",
            "wwwroot/lib/abp-web-resources/libs/abp.jquery.js",
            "wwwroot/lib/abp-web-resources/libs/abp.layer.js",
            "wwwroot/lib/moment/moment.min.js",
            "wwwroot/lib/lodash/lodash.min.js",
            "wwwroot/lib/Ydm/Ydm.js",
            "wwwroot/lib/easyui-helper/easyui-helper.js",
        ])
            .pipe(uglify())
            .pipe(concat("jui.min.js"))
            .pipe(gulp.dest("wwwroot/lib/jui/js/"))
    ];

    return merge(streams);
});


// Dependency Dirs
var deps = {
    //"jquery": {
    //    "dist/*": ""
    //},
    //"abp-web-resources": {
    //    "Abp/Framework/scripts/**": ""
    //},
    //"lodash": {
    //    "lodash*.*": ""
    //},
    //"bootstrap": {
    //    "dist/**/*": ""
    //},
    //"vue": {
    //    "dist/*": ""
    //},
    //"jquery.cookie": {
    //    "jquery.cookie.js":""
    //},
    //"vue-resource": {
    //    "dist/*": ""
    //},
    //"layer": {
    //    "layer.min.js":""
    //},
    //"cookieconsent": {
    //    "build/*": ""
    //},
    //"highlightjs": {
    //    "*.js": "",
    //    "styles/*": "styles"
    //},

    //"respond.js": {
    //    "dest/*": ""
    //},
    //"tether": {
    //    "dist/**/*": ""
    //},
    //"vee-validate": {
    //    "dist/*": ""
    //},
    //"element-ui": {
    //    "packages/alert/**/*": ""
    //},
    //"@fortawesome/fontawesome-free-webfonts": {
    //    "**/*": ""
    //}
};

//gulp.task("clean", function (cb) {
//    return rimraf("wwwroot/lib/", cb);
//});

//gulp.task("scripts", function () {

//    var streams = [];

//    for (var prop in deps) {
//        console.log("Prepping Scripts for: " + prop);
//        for (var itemProp in deps[prop]) {
//            streams.push(gulp.src("node_modules/" + prop + "/" + itemProp)
//                .pipe(gulp.dest("wwwroot/lib/" + prop + "/" + deps[prop][itemProp])));
//        }
//    }

//    return merge(streams);

//});

//gulp.task("default", gulp.series('clean', 'scripts', 'minify'));